<?php

/**
 * Description of Application_Model_Fields_Abstract
 *
 * @author Jean Brito
 */
abstract class Application_Model_Fields_Abstract {

	protected $_name='';
	protected $_sqlField='';
	protected $_sqlType='varchar';
	protected $_sqlSize=255;
	protected $_model=null;
	
	public function __construct($model,$setup){
		if(isset($setup['name']))$this->_name=$setup['name'];
		$this->_sqlField=(isset($setup['sqlField'])?$setup['sqlField']:$this->_name);
		$this->_model=$model;
		
	}
	
	public function getModel(){
		return $this->_model;
	}
	
	public function getName(){
		return $this->_name;
	}
	
	public function getSqlFieldName(){
		return $this->_sqlField;
	}
	
	public function getSqlSelect(){
		return $this->getSqlFieldName().' as '.$this->_name;
	}
	
	public function getSqlWhere($value=''){
		return "(".$this->getSqlFieldName()."='".$value."')";
	}
	
	public function getSqlCreate(){
		return $this->getSqlFieldName().' '.$this->_sqlType.($this->_sqlSize==0?'':'('.$this->_sqlSize.')');
	}
	
	public function getSqlSet($value=''){
		return "'".$value."'";
	}
	public function setValue(&$row,$value=''){
		$row[$this->_name]=$value;
		return $row;
	}
}
